/**
 * 
 */

package com.wutianyi.arithmetic;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;

/**
 * 消息摘要认证
 * 
 * @author wutianyi
 * 
 */
public class MyMessageDigestCert {

	public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
		String message = "wutianyi_test";
		byte[] plainText = message.getBytes("utf8");
		KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD5");
		SecretKey md5Key = keyGenerator.generateKey();
		
		Mac mac = Mac.getInstance("HmacMD5");
		mac.init(md5Key);
		mac.update(plainText);
		System.out.println(mac.getProvider().getInfo());
		System.out.println(new String(mac.doFinal(), "utf8"));
	}
}
